package com.gt.common;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * @author wangdong
 * @version 1.0
 * @description
 * @date 2022/8/22 14:03
 */
public class GenerateUtil {

    /**
     * 生成流水单号
     * @return
     */
    public static String serialNumber(){
        return dateStr() + String.valueOf(randomNumber(3));
    }

    public static String serialNumber6(){
        return dateStr() + String.valueOf(randomNumber(6));
    }

    public static String publicSerialNumber(){
        return "us_" + GenerateUtil.dateStr() + String.valueOf(GenerateUtil.randomCode());
    }

    public static void main(String[] str){
       String ss= "us_" + GenerateUtil.dateStr() + String.valueOf(GenerateUtil.randomCode());
        publicSerialNumber();

    }


    /**
     * 根据参数随机生成随机数
     * @return
     */
    public static int randomNumber(int number){
        return (int)((Math.random()*9+1));
    }

    public static String randomCode() {
        StringBuilder str = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < 6; i++) {
            str.append(random.nextInt(10));
        }
        return str.toString();
    }

    /**
     * 生成当前年月日时分秒字符串
     * @return
     */
    public static String dateStr(){
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String s8 = formatter.format(currentTime);
        return s8.replace(" ", "").replace("-","").replace(":","");
    }

    public static UUID uuid(){
        UUID uuid4 = UUID.randomUUID();
        int version4 = uuid4.version();

        return uuid4;

    }

}
